package com.qiwenshare.stock.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qiwenshare.stock.api.IGuessDailyService;
import com.qiwenshare.stock.domain.GuessDailyBean;
import com.qiwenshare.stock.mapper.GuessDailyBeanMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GuessDailyService implements IGuessDailyService {

    @Resource
    private GuessDailyBeanMapper guessDailyBeanMapper;

    @Override
    public int insertGuessDaily(GuessDailyBean guessDailyBean) {
        return guessDailyBeanMapper.insert(guessDailyBean);
    }

    @Override
    public int updateGuessDaily(GuessDailyBean guessDailyBean) {
        return guessDailyBeanMapper.updateById(guessDailyBean);
    }

    @Override
    public List<GuessDailyBean> getGuessDaily(String stockNum) {
        LambdaQueryWrapper<GuessDailyBean> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(GuessDailyBean::getStockNum, stockNum);

        return guessDailyBeanMapper.selectList(lambdaQueryWrapper);
    }

    @Override
    public boolean exist(String stockNum, String priceDate) {
        LambdaQueryWrapper<GuessDailyBean> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(GuessDailyBean::getStockNum, stockNum);
        lambdaQueryWrapper.eq(GuessDailyBean::getPriceDate, priceDate);
        return guessDailyBeanMapper.exists(lambdaQueryWrapper);
    }
}
